package cn.zzdt4j.config.toolkit;

import cn.hutool.core.util.StrUtil;

import java.nio.file.Paths;
import java.util.Objects;

/**
 * @author by <a href="mailto:ligang941012@gmail.com">gang.Li</a>
 * @since 2023/10/30 1:46
 */
public class EnvUtil {

    public static final String ZZDT4J_HOME_KEY = "zzdt4j.home";

    public static final String STANDALONE_MODE_PROPERTY_NAME = "zzdt4j.standalone";

    private static String zzdt4jHomePath = null;

    private static Boolean isStandalone = null;

    /**
     * Get zzdt4j home.
     *
     * @return
     */
    public static String getzzdt4jHome() {
        if (StrUtil.isBlank(zzdt4jHomePath)) {
            zzdt4jHomePath = System.getProperty(ZZDT4J_HOME_KEY);
            if (StrUtil.isBlank(zzdt4jHomePath)) {
                zzdt4jHomePath = Paths.get(System.getProperty("user.home"), "zzdt4j").toString();
            }
        }
        return zzdt4jHomePath;
    }

    /**
     * Standalone mode or not.
     *
     * @return
     */
    public static boolean getStandaloneMode() {
        if (Objects.isNull(isStandalone)) {
            isStandalone = Boolean.getBoolean(STANDALONE_MODE_PROPERTY_NAME);
        }
        return isStandalone;
    }
}
